#include "../server.hpp"

class EchoServer
{
private:
    Tcp_Server _server;
     void OnContencted(const PtrConnection &con)
    {
        DBG_LOG("New contention%p", con.get());
    }

    void OnClose(const PtrConnection &con)
    {
        DBG_LOG("Close contention%p", con.get());
    }
    void OnMessage(const PtrConnection &con, Buffer *buf)
    {
        con->Send(buf->ReadPosition(), buf->ReadAblesize());
        buf->MoveReadOffset(buf->ReadAblesize());
        con->Shutdown();
    }
public:
    EchoServer(int port) : _server(port)
    {
        _server.SetTreadCount(5);
        _server.EnableInactiveRelease(10);
        _server.SetClosedCallback(std::bind(&EchoServer::OnClose,this,std::placeholders::_1));
        _server.SetConnectedCallback(std::bind(&EchoServer::OnContencted,this,std::placeholders::_1));
        _server.SetMessageCallback(std::bind(&EchoServer::OnMessage,this,std::placeholders::_1,std::placeholders::_2));
    }
    void Start(){
        return _server.Start();
    }
   
};